import sys
import os

# 设置项目根目录路径并加入搜索路径
BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../"))
if BASE_DIR not in sys.path:
    sys.path.insert(0, BASE_DIR)

# 现在导入模块
from src.preprocessing.country_utils import read_country_list
from src.preprocessing.file_processor import process_file

def process_all_files(input_dir, country_list_path, output_dir, file_format='csv'):
    country_dict = read_country_list(country_list_path, file_format=file_format)
    for file_name in os.listdir(input_dir):
        if file_name.endswith("_Indicators.xlsx"):
            file_path = os.path.join(input_dir, file_name)
            process_file(file_path, country_dict, output_dir)

if __name__ == "__main__":
    input_directory = os.path.join(BASE_DIR, "data", "1_dataset_conversion", "origin")
    country_list_file = os.path.join(BASE_DIR, "data", "1_dataset_conversion", "country_name_mapping.csv")
    output_directory = os.path.join(BASE_DIR, "data", "1_dataset_conversion", "processed")
    
    os.makedirs(output_directory, exist_ok=True)
    process_all_files(input_directory, country_list_file, output_directory, file_format='csv')
